<template>
    <input-noborder  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="item.isReadOnly||readonly"  v-if="type=='text'"></input-noborder>
    <input-select ref="inputSelect" :attribute="item" :id="item.id" :valsql="item.valsql" :sign="item.sign" :time="item.time" isBorder="N" :dataField="dataField" styles="width:100%" :options="options" :index="index" :exkey="item.exkey"  :data="data"  @input="tableChangeData" :isreadonly="item.isReadOnly" v-else></input-select>
                       
</template>
<script>
export default {
    name: "input-xm",
    props:["item","dataField","data","index","readonly","appid"],
    data(){
        return{
            type:"text",
            options:[]
        }
    },
    components: {
       inputNoborder: function (resolve) {
            //异步组件写法
            require(['./input-noborder'], resolve)
        },
       inputSelect: function (resolve) {
            //异步组件写法
            require(['./input-select'], resolve)
        }
    },
    created(){
        this.loadSubItem();
    },
    methods:{
        tableChangeData(item){
            this.$emit("input",item);
        },
        loadSubItem(){
            let amt=this.data[this.dataField][this.index]["szi_ex2"];
            let sf_id=this.data[this.dataField][this.index]["szi_ex8"];
        
            this.$post(this.appid,"/byg/funeral/getSubItem",{sf_id:sf_id}).then(data=>{
                let options=[];
                let isOk=false;
                for(let i=0;i<data.length;i++){
                    let d=data[i];
                    d.optname=d.ssf_ex2;
                    d.optvalue=d.ssf_ex2;
                    options.push(d);

                    try{
                        if(Number(amt)==Number(d.ssf_ex2)){
                            isOk=true;
                        }
                    }catch(e){}
                }
                
                if(!isOk){
                    let d={};
                    d.optname=amt;
                    d.optvalue=amt;
                    options.push(d)
                }
                if(options.length<=1){
                    this.type="text"
                }else{
                    this.type="select"
                }
                this.options=options;
                //this.$refs.tableEditss.setDataSource(this.data[this.dataField].length-1,options)
            });
        },
    },
    
}
</script>